<div class="layuimini-container layuimini-page-anim">
    <div class="layuimini-main">

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit"
               href="/#/page/rsb/unattendance.html?employNameForm={{d.userName}}" >详情</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
        </script>

    </div>
</div>
<script>
    $(function () {
        layui.use(['form', 'table', 'miniPage', 'element'], function () {
            var $ = layui.jquery,
                form = layui.form,
                table = layui.table,
                miniPage = layui.miniPage;


            table.render({
                elem: '#currentTableId',
                height: 800,
                url: '/selectAllAttendance',
                toolbar: '#toolbarDemo',
                defaultToolbar: ['filter', 'exports', 'print', {
                    title: '提示',
                    layEvent: 'LAYTABLE_TIPS',
                    icon: 'layui-icon-tips'
                }],
                cols: [[
                    {field: 'rsbAtNum', width: 100, title: '编号'},
                    {field: 'userNum', width: 130, title: '员工编号'},
                    {field: 'userName', width: 100, title: '姓名'},
                    {field: 'rsbAtDay', width: 140, title: '本月应上班天数', sort: true},
                    {field: 'rsbAtTrueday', width: 140, title: '实际上班天数'},
                    {field: 'rsbAtFalseday', width: 135, title: '缺勤天数'},
                    {field: 'rsbAtAddtimes', width: 135, title: '加班时长'},
                    {title: '审批操作', minWidth: 120, toolbar: '#currentTableBar', align: "center"}
                ]]
            });




            //监听表格复选框选择
            table.on('checkbox(currentTableFilter)', function (obj) {
                console.log(obj)
            });

            table.on('tool(currentTableFilter)', function (obj) {
                var data = obj.data;
                if (obj.event === 'delete') {
                    var num=data.rsbAtNum;
                    layer.confirm('真的删除编号'+num+'吗？',{btn:['是的,我确定','我再想想']}, function (index) {
                        /*obj.del();
                        layer.close(index);*/
                        $.ajax({
                            url:"/deleteRsbAttendance",
                            dataType:'json',
                            data:{
                                rsbAtNum:num
                            }
                        })
                        obj.del();
                        layer.close(index);
                    });
                }
            });

        });


        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;

            /**
             * 初始化表单，要加上，不然刷新部分组件可能会不加载
             */
            form.render();

            //日期
            laydate.render({
                elem: '#date'
            });
            laydate.render({
                elem: '#date1'
            });

            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');

            //自定义验证规则
            form.verify({
                title: function (value) {
                    if (value.length < 5) {
                        return '标题至少得5个字符啊';
                    }
                }
                , pass: [
                    /^[\S]{6,12}$/
                    , '密码必须6到12位，且不能出现空格'
                ]
                , content: function (value) {
                    layedit.sync(editIndex);
                }
            });

            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            });

            //监听提交
            form.on('submit(demo1)', function (data) {
                layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                })
                return false;
            });

            //表单初始赋值
            form.val('example', {
                "username": "贤心" // "name": "value"
                , "password": "123456"
                , "interest": 1
                , "like[write]": true //复选框选中状态
                , "close": true //开关状态
                , "sex": "女"
                , "desc": "我爱 layui"
            })

            form.on('select(dep)', function (data) {
                var url = "/showPost?dep=" + data.value;
                $.get(url, function (data) {
                    var tmp = '<option value="">请选择</option>';
                    for (var i in data) {
                        tmp += '<option value="' + data[i] + '">' + data[i] + '</option>';
                    }
                    $("#rsbMonPost").html(tmp);
                    //重载select模块，否则不会展示
                    layui.form.render("select");
                });
            })
        });
    })
</script>
<style>
    ::-webkit-scrollbar{
        height: 13px;
    }
</style>